// 属性访问控制
// 还可以实现用属性装饰器来进行访问控制器或者设置初始值

function defaultValue(value: any) {
  return function (target: any, propertyKey: string) {
    const instanceKey = Symbol(propertyKey);

    Object.defineProperty(target, propertyKey, {
      get: function () {
        if (this[instanceKey] === undefined) {
          this[instanceKey] = value;
        }
        return this[instanceKey];
      },
      set: function (newVal) {
        this[instanceKey] = newVal;
      },
      enumerable: true,
      configurable: true
    });
  };
}

class Settings {
  @defaultValue('dark')
  theme: string;

  @defaultValue(1000)
  timeout: number;
}

const settings = new Settings();
console.log(settings.theme);  // 输出: dark
console.log(settings.timeout); // 输出: 1000

export { }
